package com.business.yang.core;

import android.content.Intent;
import android.os.Bundle;

import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
import com.business.yang.R;
import com.business.yang.mvp.view.find.activity.FindActivity;
import com.business.yang.mvp.view.home.activity.HomeActivity;
import com.business.yang.mvp.view.my.activity.MyActivity;
import com.lyxs916.corelib.core.application.ActivityManager;
import com.lyxs916.appbaselibrary.core.activity.BaseMvpActivity;
import com.lyxs916.appbaselibrary.core.iview.BaseView;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;
import com.lyxs916.utilslibrary.ui.DrawableUtils;

import butterknife.BindView;

/**
 * 说明:
 * 作者： 杨阳; 创建于：  2017-06-06  15:29
 */
public abstract class BaseMainActivity<V extends BaseView, P extends BasePresenter<V>> extends BaseMvpActivity<V, P> implements AHBottomNavigation.OnTabSelectedListener {
    @BindView(R.id.bottom_navigation_bar)
    public AHBottomNavigation ahBottomNavigation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
//        ahBottomNavigation= (AHBottomNavigation) findViewById(R.id.bottom_navigation_bar);

        ahBottomNavigation.setAccentColor(getResources().getColor(R.color.primary));

        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.home),
                DrawableUtils.getStateSelectDrawable(mActivity,R.mipmap.ic_launcher, R.mipmap.ic_launcher_round)));

        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.find),
                DrawableUtils.getStateSelectDrawable(mActivity,R.mipmap.ic_launcher, R.mipmap.ic_launcher_round)));

        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.my),
                DrawableUtils.getStateSelectDrawable(mActivity,R.mipmap.ic_launcher, R.mipmap.ic_launcher_round)));

        ahBottomNavigation.setDefaultBackgroundColor(getResources().getColor(R.color.gray_ee));
        ahBottomNavigation.setCurrentItem(currentItem(), true);
        ahBottomNavigation.setOnTabSelectedListener(this);
        ahBottomNavigation.setBehaviorTranslationEnabled(false);
//        ahBottomNavigation.setTitleTextSize(25, 20);//设置文字的大小，选中时和没有选中时。

    }

    @Override
    public void parseIntent(Intent intent) {
    }

    @Override
    protected void onResume() {
        super.onResume();
        ahBottomNavigation.setCurrentItem(currentItem(), false);

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    public abstract int currentItem();

    @Override
    public boolean onTabSelected(int position, boolean wasSelected) {
        if (position != currentItem()) {

            if (position == 0) {
                HomeActivity.startUi(mActivity);

            } else if (position == 1) {
                FindActivity.startUi(mActivity);

            } else if (position == 2) {
                MyActivity.startUi(mActivity);
            }
        }
        return true;
    }
    @Override
    public void onBackPressed() {
        ActivityManager.getInstance().isExitApplication(this);
    }
}
